package com.fenghuajueli.libbasecoreui.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.fenghuajueli.libbasecoreui.R;
import com.fenghuajueli.libbasecoreui.adapter.QuitEditTipsActionAdapter;
import com.fenghuajueli.libbasecoreui.listener.OnListClickListener;

import java.util.List;

/**
 * 退出编辑时的操作提示对话框
 */
public class QuitEditTipsDialog extends BaseBottomDialog {

    private OnListClickListener<String> onListClickListener;

    private TextView tvTitle;
    private ListView actionListView;
    private QuitEditTipsActionAdapter quitEditTipsActionAdapter;
    private List<String> actionList;
    private String tvTitleName;

    public QuitEditTipsDialog(@NonNull Context context, List<String> actionList) {
        super(context);
        this.actionList = actionList;
    }

    public QuitEditTipsDialog(@NonNull Context context, String title, List<String> actionList) {
        super(context);
        this.actionList = actionList;
        tvTitleName = title;
    }

    public void setOnListClickListener(OnListClickListener<String> onListClickListener) {
        this.onListClickListener = onListClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_quit_edit_tips_layout);
        actionListView = findViewById(R.id.actionListView);
        tvTitle = findViewById(R.id.tvTitle);
        if (actionList == null || actionList.size() == 0) {
            dismiss();
            return;
        }
        if (!TextUtils.isEmpty(tvTitleName)) {
            tvTitle.setText(tvTitleName);
        }
        quitEditTipsActionAdapter = new QuitEditTipsActionAdapter(getContext(), actionList);
        quitEditTipsActionAdapter.setOnListClickListener(new OnListClickListener<String>() {
            @Override
            public void itemClick(int position, String data) {
                if (onListClickListener != null) {
                    onListClickListener.itemClick(position, data);
                }
            }
        });
        actionListView.setAdapter(quitEditTipsActionAdapter);
    }


    @Override
    public void dismiss() {
        super.dismiss();
    }
}
